from datetime import datetime

from sqlalchemy import String, DateTime, Boolean, Enum as SAEnum
from sqlalchemy.orm import Mapped, mapped_column
from enum import Enum as PyEnum

from app.core.database import Base


class VerificationPurpose(str, PyEnum):
    REGISTER = "register"
    RESET_PASSWORD = "reset_password"


class VerificationCode(Base):
    __tablename__ = "verification_codes"

    phone: Mapped[str] = mapped_column(String(20), index=True, nullable=False)
    code: Mapped[str] = mapped_column(String(6), nullable=False)
    purpose: Mapped[VerificationPurpose] = mapped_column(
        SAEnum(VerificationPurpose, name="verification_purpose"), nullable=False
    )
    is_used: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
    expires_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
